home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / DIAHRAD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  3.9 KB  |  204 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // DialogClass
  8. // DiaHorizRadioButton
  9. //
  10.  
  11. #include "fli.h"
  12. #include "elements.h"
  13. #include "colors.h"
  14.  
  15. #ifdef __BCPLUSPLUS__
  16. #pragma hdrstop
  17. #endif
  18.  
  19. #include <string.h>
  20. #include <alloc.h>
  21.  
  22. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23. //
  24. // DiaHorizRadio()
  25. //
  26. // Constructor for DiaHorizRadio
  27. //
  28. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  29.  
  30. DiaHorizRadio::DiaHorizRadio(int _X,int _Y,int &_Item,int _ItemCount,char **_Items) :
  31.   Item(_Item),
  32.   Items(_Items),
  33.   ItemCount(_ItemCount)
  34. {
  35.   X=_X;
  36.   Y=_Y;
  37.  
  38.   IsQueued=0;
  39.  
  40.   int i, j=0;
  41.  
  42.   if (_ItemCount)
  43.   {
  44.     for (i=0;i<_ItemCount;i++)
  45.       j+=(strlen(_Items[i])+5);
  46.  
  47.     j++;
  48.   }
  49.  
  50.   Width=j;
  51.   Height=1;
  52. }
  53.  
  54. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  55. //
  56. // ~DiaHorizRadio()
  57. //
  58. // Destructor for DiaHorizRadio
  59. //
  60. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  61.  
  62. DiaHorizRadio::~DiaHorizRadio()
  63. {
  64.   if (IsQueued)
  65.     free(Items);
  66. }
  67.  
  68. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  69. //
  70. // operator +
  71. //
  72. // Quick method to defining radio buttons
  73. //
  74. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  75.  
  76. void DiaHorizRadio::operator+ (char *Item)
  77. {
  78.   if (!IsQueued && Items)
  79.     return;
  80.  
  81.   if (!IsQueued)
  82.     Width=1;
  83.  
  84.   IsQueued++;
  85.   Items=(char **)realloc(Items,sizeof(char *)*++ItemCount);
  86.   Items[ItemCount-1]=Item;
  87.  
  88.   Height=1;
  89.   Width+=(strlen(Item)+5);
  90. }
  91.  
  92. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  93. //
  94. // Show()
  95. //
  96. // Show the radio buttons
  97. //
  98. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  99.  
  100. void DiaHorizRadio::Show()
  101. {
  102.   MouseHide();
  103.  
  104.   int Avail=(Available()==CompleteEvent);
  105.  
  106.   (*Blaze) (X,Y) << ((Avail)?Colors.RadioText:Colors.DiaDeadLocator) << ' ';
  107.  
  108.   if (Item>=ItemCount)
  109.     Item=ItemCount-1;
  110.  
  111.   if (Item<0)
  112.     Item=0;
  113.  
  114.   for (int i=0;i<ItemCount;i++)
  115.   {
  116.     (*Blaze)
  117.       << ((Avail)?Colors.RadioText:Colors.DiaDeadLocator)
  118.       << '('
  119.       << ((Avail)?((i==Item)?Colors.RadioCheckMark:Colors.RadioText):Colors.DiaDeadLocator)
  120.       << ((i==Item)?'\x7':' ')
  121.       << ((Avail)?Colors.RadioText:Colors.DiaDeadLocator)
  122.       << ") "
  123.       << Items[i]
  124.       << ' ';
  125.   }
  126.  
  127.   MouseShow();
  128. }
  129.  
  130. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  131. //
  132. // HighLight()
  133. //
  134. // Highlight the current radio button
  135. //
  136. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  137.  
  138. void DiaHorizRadio::HighLight()
  139. {
  140.   MouseHide();
  141.  
  142.   for (int i=0,j=0;i<Item;i++)
  143.     j+=(strlen(Items[i])+5);
  144.  
  145.   Blaze->LineAttribute(X+j,Y,strlen(Items[Item])+6,
  146.     Colors.RadioHiLite);
  147.   Blaze->WindowGotoXY(X+j+2,Y);
  148.  
  149.   MouseShow();
  150. }
  151.  
  152. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  153. //
  154. // EventHandler()
  155. //
  156. // Handles the events
  157. //
  158. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  159.  
  160. int DiaHorizRadio::EventHandler(int Event)
  161. {
  162.   if (Event==kbRight || Event==' ')
  163.   {
  164.     if (ItemCount>1)
  165.     {
  166.       Item=(Item==ItemCount-1)?0:(++Item);
  167.       Show();
  168.       HighLight();
  169.     }
  170.     return CompleteEvent;
  171.   }
  172.  
  173.   if (Event==kbLeft)
  174.   {
  175.     if (ItemCount>1)
  176.     {
  177.       Item=(!Item)?(ItemCount-1):(--Item);
  178.       Show();
  179.       HighLight();
  180.     }
  181.     return CompleteEvent;
  182.   }
  183.  
  184.   if (Event==ValidatedMousedEvent && MouseEvent&MouseLeftButtonRelease)
  185.   {
  186.     MouseHorizontal-=X;
  187.  
  188.     int Position=0;
  189.     int Current=0;
  190.  
  191.     do
  192.       Position+=(5+strlen(Items[Current++]));
  193.     while (MouseHorizontal>Position);
  194.  
  195.     Current--;
  196.     Item=Current;
  197.     Show();
  198.     HighLight();
  199.     return CompleteEvent;
  200.   }
  201.  
  202.   return Event;
  203. }
  204.